<?php
/**
 *@file commentban.php
 *@author Zhe.Zhou(zhouzhe@haibao.com)
 *@date 2015-7-16 下午4:21:15
 *@brief  
 */
namespace haibao\comment\data;

class CommentBan extends \haibao\cms\data\BaseMysql{
	public function __construct() {
		parent::__construct ( '\haibao\comment\model\data\CommentBan' );
		$this->setConfig( \haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_MYSQL_HAIBAO_USER );
	}
	public function getSeal($editInfo){
	    $resArr = array("IP"=>0,"UserId"=>0,"BanIpId"=>null,"BanUserId"=>null);
	    $ip = $editInfo->IP;
	    $userId = $editInfo->UserId;
	    $sqlIp = "select Id,IP from `CommentBan` where IP = '".$ip."' and BanStatus=".\haibao\comment\model\data\CommentBan::BAN_STATUS_NO;
	    $sqlUser = "select Id,UserId from `CommentBan` where UserId = ".$userId." and BanStatus=".\haibao\comment\model\data\CommentBan::BAN_STATUS_NO;
	    $resultIp = $this->query($sqlIp);
	    $resultUser = $this->query($sqlUser);
	    while($resultIp->fetch_assoc()){
	          $resArr['IP'] = 1;
	          $resArr['BanIpId'] = $resultIp->getData('Id');
	    }
	    while($resultUser->fetch_assoc()){
	           $resArr['UserId'] = 1;
	           $resArr['BanUserId'] = $resultUser->getData('Id');
	    }
	    return $resArr;
	}
	
	public function getBan($info,$type){
	    $resArr = array();
	    if($type==1){
	        $sql = "select Id from `CommentBan` where UserId = %s and BanType = %s";
	    }else {
	        $sql = "select Id from `CommentBan` where Ip = %s and BanType = %s";
	    }
	    $result = $this->query($sql,array($info,$type));
	    while($result->fetch_assoc()){
	        $resArr['Id'] = $result->getData('Id');
	    }
	    return $resArr;
	}
	
	public function checkUserIsBan($userId,$ip){
		$sql = 'select Id from `CommentBan` where (UserId=%s or Ip=%s) and BanStatus=%s';
		$result = $this->query($sql,array($userId,$ip,\haibao\comment\model\data\CommentBan::BAN_STATUS_NO))->fetch_assoc();
		if($result){
			return true;
		}
		return false;
	}
	

}